package com.example.assignment01_javaee.Controller;

import com.example.assignment01_javaee.Entity.Employee;
import com.example.assignment01_javaee.Entity.Supplier;
import com.example.assignment01_javaee.Service.EmployeeService;
import com.example.assignment01_javaee.Service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class SupplierController {

    @Autowired
    SupplierService supplierService;

    //获取全部供应商信息
    @GetMapping("/suppliers")
    public ResponseEntity<List<Supplier>> getAllSuppliers(){
        return ResponseEntity.ok(supplierService.getAllSuppliers());
    }
    //通过id获取某个供应商信息
    @GetMapping ("/suppliers/{supplierId}")
    public ResponseEntity<Supplier> getSupplierById(@PathVariable Integer supplierId){
        return ResponseEntity.ok(supplierService.getSupplierById(supplierId));
    }
    //增加供应商
    @PostMapping("/suppliers")
    public String createSupplier(@RequestBody Supplier supplier){
        return supplierService.createSupplier(supplier);
    }

    //根据id更新供应商信息
    @PutMapping("/suppliers/{supplierId}")
    public String updateSupplierById(@RequestBody Supplier supplier, @PathVariable Integer supplierId){
        supplier.setSupplierId(supplierId);
        return supplierService.updateSupplierById(supplier);
    }
    //删除供应商
    @DeleteMapping("/suppliers/{supplierId}")
    public String deleteSupplierById(@PathVariable Integer supplierId){
        return supplierService.deleteSupplierById(supplierId);
    }

}
